<template>
	<view class="uni_box home">
		<!-- <navbar title='安全中心' :yin="false">
		</navbar> -->
		<image class="img_bj" src="/static/home/login.jpg"/>
		<view class="loginview">
			<view class="lone">
				<u-icon name="arrow-left" color="#fff" size="40" class="lfan" @click="getfan"></u-icon>
				<!-- <image class="lfan" src="/static/img/icon_back.png" @click="getfan"/> -->
				<text class="Loginname" @click="yanClick">{{ !isyan?'验证码登录':'密码登录' }}</text>
			</view>
			<view class="content">
				<view class="logoview">
					<image class="logos" src="/static/home/logos.png"/>
				</view>
				<view class="uone" >
					<view class="ushuru">
						<image class="yanicon" src="/static/home/shouji.png"/>
						<u-input v-model="account" type="text" :border="false" placeholder="用户名/邮箱/手机"/>
					</view>
				</view>
				<view class="uone" v-if="!isyan">
					<view class="ushuru">
						<image class="yanicon" src="/static/home/mimaicon.png"/>
						<u-input v-model="password" type="password" :border="false" placeholder="请输入密码"/>
					</view>
				</view>
				<view class="uone" v-if="!isyan">
					<view class="ushuru">
						<image class="yanicon" src="/static/home/yanicons.png"/>
						<u-input v-model="captcha" type="text" :border="false" placeholder="请输入验证码"/>
						<view class="yanmaview">
							<image class="maviewimg" :src="maimg"/>
						</view>
						<image class="zhuan" @click="getma" src="/static/home/zhuan.png"/>
					</view>
				</view>
				<view class="uone" v-if="isyan">
					<view class="ushuru">
						<u-input v-model="code" type="text" :border="false" placeholder="请输入验证码"/>
						<view class="huoqu"  v-if="isTimer">{{time}}s</view>
						<view class="huoqu" v-else @click="lockSheet">获取验证码</view>
					</view>

				</view>
				<view class="sbotview">
					<view class="tologin " v-if="!isyan"  :class="phone&&password?'btn':''" @click="getlogin">登录</view>
					<view class="tologin " v-if="isyan"  :class="phone&&code?'btn':''" @click="getlogin">登录</view>
					<!-- <text class="No-account" @click="zhuce">没有帐号<text class="zhutit">注册</text></text> -->
				</view>
				
				<view class="yanlogin">
					<!-- <text class="Forgot-password" @click="wangji">忘记密码？</text> -->
					<text class="Forgot-password"  @click="wangji">忘记密码</text>
					<text class="Forgot-password" style="margin-left: auto;" @click="zhuce">注册</text>
				</view>
				

				<view class="yandeng">
					<text class="fangshi">OR</text>
					<view class="otherlogin">
						<view class="oview">
							<image class="livon" src="/static/home/qq.png"/>
						</view>
						<view class="oview">
							<image class="livon" src="/static/home/wei.png"/>
						</view>
						<view class="oview">
							<image class="livon" src="/static/home/weibo.png"/>
						</view>
					</view>
					<!-- <image class="icon_wx" @click="getwechat" src="/static/img/icon_wx.png"/> -->
					<!-- <view class="yinview" @click.stop="isgou=!isgou">
						<image class="yueicon" src="/static/img/icon_xz_s.png" v-if="isgou"/>
						<image class="yueicon" src="/static/img/icon_xz_n.png" v-if="!isgou"/>
						<text class="yuedu">已阅读并同意 <text class="xies" @click="xieyi(1)">《用户协议》</text>  及 <text class="xies"  @click="xieyi(2)">《隐私政策》</text></text>
					</view> -->
				</view>
				

				
			</view>
		</view>
		

		<u-select v-model="bshow" :list="blist" @confirm="bconfirm"></u-select>
	</view>
</template>

<script>
import {
		baseUrl
	} from '@/utils/config.js';
	export default {
		data() {
			return {
				value:'',
				wang:'',
				bshow:false,
				blist:[
					{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				// phone:'13555555555',
				// password:'111111',
				phone:'',
				
				isyan:false,
				code:'',
				isgou:false,

				timer: null,
				time: 60,
				isTimer: false,

				account:'',
				password:'',
				captcha:'',
				maimg:''
			}
		},
		onLoad() {
			this.getma()
		},
		onShow() {
		},
		methods: {
			async getma(){
				// console.log(Math.random())
				// let res = await this.$u.api.captcha({
				// 	// s:'/captcha',
				// 	id:Math.random()
				// });
				// console.log(res)
				uni.request({
					url: baseUrl+'/api/v1.common/captcha', // 你的API接口地址
					method: 'GET', // 请求方法，可选值：OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
					data: {
						// 你要发送的数据
						id:Math.random()
					},
					responseType: "arraybuffer", //这是必要的一步,responseType必须设置为arraybuffer 
					// responseType: 'arraybuffer',//必填项，否则保存不了arrayBuffer格式
					header: {
						'content-type': 'application/json' // 设置请求的 header
					},
					success: (res) => {
						// 请求成功的处理
						// console.log(res.data);
						// this.maimg = res.data
						this.maimg = `data:image/jpeg;base64,${uni.arrayBufferToBase64(res.data)}` 
					},
					fail: (err) => {
						// 请求失败的处理
						console.error(err);
					}
				});

			},
			async getlogin(){
				
				if(!this.isyan){ //账号密码登录
					if(!this.account){
						this.$u.toast('请输入账号');
						return false
					}
					if(!this.password){
						this.$u.toast('请输入密码');
						return false
					}
					// if(!this.isgou){
					// 	this.$u.toast('请先勾选协议');
					// 	return false
					// }
					let res = await this.$u.api.login({
						account:this.account,
						password:this.password,
						captcha:this.captcha
					});
					console.log(res)
					this.$store.commit('changeToken', res.userinfo.token);
					// this.$store.commit('changeJiaose', data.jiaose);
					this.$u.toast('登录成功');
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tabbar/Tabhome'
						})
					}, 1000);
				}else{
					if(!this.phone){
						this.$u.toast('请输入手机号');
						return false
					}
					if(!this.code){
						this.$u.toast('请输入验证码');
						return false
					}
					if(!this.isgou){
						this.$u.toast('请先勾选协议');
						return false
					}
					let res = await this.$u.api.loginlindx({
						phone:this.phone,
						code:this.code
					});
					console.log(res)
					this.$store.commit('changeToken', res.token);
					// this.$store.commit('changeJiaose', data.jiaose);
					this.$u.toast('登录成功');
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tabbar/Tabhome'
						})
					}, 1000);
				}
				
			},
			xuanwang(){
				this.bshow = true
			},
			bconfirm(e){
				console.log(e)
				this.wang = e[0].value
			},
			wangji(){
				this.navrouter("/pages/login/ForgetPsd");
			},
			zhuce(){
				this.navrouter("/pages/login/register");
			},
			getfan(){
				uni.navigateBack()
			},
			getwechat(){
				this.navrouter("/pages/login/loginWeChat");
			},
			yanClick(){
				this.isyan = !this.isyan
			},
			xieyi(e){
				if(e == 1){
					//用户协议
					this.navrouter("/pages/TPage/Xieyi?type=agreement");
				}else if(e == 2){
					//隐私协议
					this.navrouter("/pages/TPage/Xieyi?type=privacy");
				}
			},
			async lockSheet() {
				if(!this.phone){
					this.$u.toast("请输入手机号");
					return false;
				}
				
				let res = await this.$u.api.sendEmail({
					phone: this.phone,
					scene:'login'
				});
				this.isTimer = true;
				this.timer = setInterval(() => {
					this.time--
					if (this.time < 0) {
						this.isTimer = false;
						this.time = 60;
						clearInterval(this.timer);
					};
				}, 1000);
				this.$u.toast("发送成功");
				// this.yanshow = true
				// this.initYpRiddler()
				// this.$refs.captcha.initYpRiddler();
				// this.$refs.captcha.verify();
			},

		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.uni_box{
		position: relative;
		min-height: 100vh;
	}
	.img_bj{
		position: absolute;
		width: 100%;
		height: 108%;
	}
	.loginview{
		position: relative;
	}
	.lone{
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 40rpx;
		// #ifdef APP-PLUS
		padding-top: calc(var(--status-bar-height) + 40rpx);;
		// #endif
		.lfan{
			width: 40rpx;
			height: 40rpx;
			margin-right: 20rpx;

		}
		.Loginname{
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #FFFFFF;
			margin-left: auto;
		}
	}
	.logoview{
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-bottom: 60rpx;
		.logos{
			width: 230rpx;
			height: 230rpx;
		}
		// margin-bottom: 60rpx;
		.loginname{
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 60rpx;
			color: #333333;
		}
		.loginmiao{
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #666666;
			margin-top: 15rpx;
			display: block;
		}
		.loview{
			position: absolute;
			width: 100%;
			height: 100%;
			border-radius: 40rpx;
			display: block;
			
		}
		.lmiaoshu{
			display: flex;
			flex-direction: column;
			margin: 50rpx 0 30rpx;
			.mview{
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-bottom: 15rpx;
				.icon_zj{
					width: 28rpx;
					height: 28rpx;
					margin-right: 10rpx;
				}
				.dai{
					font-family: PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #496EE7;
				}
			}
		}
	}
	.chongji{
		width: 38rpx;
		height: 36rpx;
	}
	.content{
		// background-color: #fff;
		padding: 30rpx 60rpx;
		.mpone{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-bottom: 80rpx;
			.touview{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				margin-right: 30rpx;
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			.tou2{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				position: absolute;
			}
			.xj{
				position: relative;
				z-index: 1;
				width: 42rpx;
				height: 38rpx;
			}
			.mpright{
				flex: 1;
				display: flex;
				flex-direction: column;
				.yxname{
					font-family: Source Han Sans CN;
					font-weight: bold;
					font-size: 24rpx;
					color: #000000;
				}
				.to lo g i nview{
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-top: 10rpx;
					.idnum{
						font-family: Source Han Sans CN;
						font-weight: 400;
						font-size: 24rpx;
						color: #000000;
						display: inline-block;
						margin-right: 13rpx;
					}
					.dengji{
						padding: 5rpx 30rpx;
						background: #FF8004;
						border-radius: 14rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						font-size: 20rpx;
						color: #FFFFFF;
					}
				}
			}
		}
		.qian{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-bottom: 45rpx;
			.qbiao{
				display: inline-block;
				width: 8rpx;
				height: 36rpx;
				background: #FF8004;
				margin-right: 8rpx;

			}
			.qname{
				font-family: Source Han Sans CN;
				font-weight: bold;
				font-size: 30rpx;
				color: #000000;
			}
		}
		.uone{
			display: flex;
			flex-direction: column;
			margin-bottom: 30rpx;
			.Input-head{
				display: flex;
				flex-direction: row;
				align-items: center;

			}
			.usdt{
				width: 46rpx;
				height: 46rpx;
				margin-right: 12rpx;
			}
			.Input-label{
				font-family: Source Han Sans CN;
				font-weight: 500;
				font-size: 30rpx;
				color: #000000;
				display: inline-block;
				margin-left: 20rpx;
			}
		}
		// .uone:last-child{
		// 	margin-bottom: 30rpx;
		// }
		.Forgot-password{
			font-weight: 500;
			font-size: 22rpx;
			color: #FFFFFF;
		}
		.ushuru{
			padding: 20rpx 0rpx;
			// background: #F7F7F7;
			// background: rgba(255,255,255,0.6);
			// border-radius: 20rpx;
			// margin-top: 20rpx;
			border-bottom: 1rpx solid rgba(255, 255, 255, 0.2);
			display: flex;
			align-items: center;
			flex-direction: row;
			min-height: 80rpx;
			/deep/.u-input__input{
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
			}
			.yanicon{
				width: 30rpx;
				height: 40rpx;
				margin-right: 20rpx;
			}
			.xuantit{
				color: #c0c4cc;
			}
			.xactive{
				font-weight: 400;
				font-size: 28rpx;
				color: #000000;
			}
			.xia{
				margin-left: auto;
				width: 16rpx;
				height: 10rpx;
			}
			.quanbu{
				margin-left: 30rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				font-family: Source Han Sans CN;
				font-weight: 400;
				font-size: 28rpx;
				color: #010101;
			}
			.yanmaview{
				width: 165rpx;
				height: 60rpx;
				margin-left: 20rpx;
				margin-right: 10rpx;
				position: relative;
				background-color: #fff;
				.maviewimg{
					position: absolute;
					width: 100%;
					height: 100%;
				}
			}
			.zhuan{
				width: 35rpx;
				height: 42rpx;
			}
			.huoqu{
				padding: 8rpx 0rpx;
				margin-left: 10rpx;
				font-weight: 500;
				font-size: 30rpx;
				color: #496EE7;
			}
		}
		.keyong{
			display: block;
			text-align: right;
			font-family: Source Han Sans CN;
			font-weight: 400;
			font-size: 22rpx;
			color: #010101;
			margin-bottom: 75rpx;
		}
		
		.sbotview{
			margin: 80rpx 0 40rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			.shoufei{
				font-family: Source Han Sans CN;
				font-weight: 400;
				font-size: 22rpx;
				color: #010101;
				display: block;
				margin-bottom: 15rpx;


			}
			.tologin{
				width: 100%;
				height: 90rpx;
				// background: #CCCCCC;
				// border-radius: 20rpx;
				background: #2A4C7E;
				box-shadow: 0rpx 0rpx 66rpx 13rpx rgba(253,192,3,0.19);
				border-radius: 42rpx;

				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #FFFEFE;
			}
			.btn{
				background: #496EE7;
				color: #fff;
			}
			.No-account{
				display: block;
				text-align: center;
				font-family: Source Han Sans CN;
				font-weight: 500;
				font-size: 26rpx;
				color: #A5A5A5;
				margin-top: 40rpx;
			}
			.zhutit{
				color: #000;
			}
		}
		.yanlogin{
			display: flex;
			flex-direction: row;
			align-items: center;

		}
		.yandeng{
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			margin: 100rpx 10rpx 30rpx;
			.fangshi{
				font-family: Myriad Pro;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				display: block;
				width: 100%;
				text-align: center;
				padding-bottom: 20rpx;
				border-bottom: 1rpx solid rgba(255, 255, 255, 0.2);

			}
			.otherlogin{
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-top: 70rpx;
				.oview{
					width: 33.33%;
					display: flex;
					align-items: center;
					justify-content: center;
					.livon{
						width: 82rpx;
						height: 82rpx;
					}
				}
			}
			.icon_wx{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				margin: 30rpx auto 40rpx;
			}
			.yinview{
				display: flex;
				flex-direction: row;
				align-items: flex-start;
				margin: 0 auto;
				.yueicon{
					margin-right: 14rpx;
					width: 36rpx;
					height: 36rpx;
				}
				.yuedu{
					font-family: PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					width: 100%;
					white-space: nowrap;
					text-align: center;

				}
				.xies{
					color: #496EE7;
				}
			}

		}
		// padding-bottom: 150rpx;
	}
</style>
